<?php
require_once(ROOTDIR.'classes/basedb.php');

class ShopDB extends BaseDB{
	public function insertShop($fieldsData){
		$fieldsData = $this->_checkShopData($fieldsData);
		if (!$fieldsData) return null;
		$sql = "INSERT INTO ".TB_HEAD."_shops SET " . $this->_getUpdateSqlString($fieldsData);
		//echo $sql.'\n';
		$this->_db_writer->update($sql);
		$insertId = $this->_db_writer->insert_id();
		return $insertId;
	}
	
	private function _checkShopData($data){
		if (!is_array($data) || !count($data)) return null;
		$data = $this->_checkAllowField($data,$this->getShopStruct());
		return $data;
	}
	
	public function getShopStruct(){
		return array('cate_id','shop_name','shop_logo','shop_url','recommend_count','taoke_url','data','sort','server_code');
	}
	
	public function checkShopUrl($shop_url){
		$sql = "select count(shop_id) as c from ".TB_HEAD."_shops where shop_url='".$shop_url."'";
		$result = $this->_db_reader->get_one($sql);
		if($result && $result['c']>=1) return TRUE;
		else return FALSE;
	}
	
	public function getShopList(){
		$sql = "select * from ".TB_HEAD."_shops limit 0,2";
		$query = $this->_db_reader->query($sql);
		$result = $this->_getAllResultFromQuery($query);
		return $result;
	}
}
?>